package com.hfut.manage.controller;
import com.hfut.manage.pojo.Result;
import com.hfut.manage.pojo.Salary;
import com.hfut.manage.service.ISalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/Salary")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @GetMapping
    public Result list() {
        return Result.success(salaryService.lambdaQuery().orderByAsc(Salary::getSalaryId).list());
    }

    @PostMapping
    public Result save(@RequestBody Salary salary) {
        salaryService.save(salary);
        return Result.success();
    }

    @PutMapping
    public Result updata(@RequestBody Salary salary){
        salaryService.updateById(salary);
        return Result.success();
    }


    @GetMapping("/{teacherid}")
    public Result getById(@PathVariable("teacherid") Long teacherId) {
        List<Salary> salaries = salaryService.lambdaQuery()
                .eq(Salary::getTeacherId, teacherId)
                .list();
        return Result.success(salaries);
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Long id) {
        boolean success = salaryService.removeById(id);
        if (!success) {
            return Result.error(500, "删除金额失败");
        }
        return Result.success();
    }
}
